package com.guigu.youxuan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.youxuan.mapper.SupplierInfoMapper;
import com.guigu.youxuan.mapper.SupplierProductMapper;
import com.guigu.youxuan.common.utils.PageUtils;
import com.guigu.youxuan.mapper.SupplierProductMapper;
import com.guigu.youxuan.pojo.GoodsCategory;
import com.guigu.youxuan.pojo.SupplierInfo;
import com.guigu.youxuan.pojo.OrderInfo;
import com.guigu.youxuan.pojo.PurchaseOrder;
import com.guigu.youxuan.pojo.SupplierProduct;
import com.guigu.youxuan.pojo.dto.SupplierGoodsDto;
import com.guigu.youxuan.service.ISupplierProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@Service
public class SupplierProductServiceImpl extends ServiceImpl<SupplierProductMapper, SupplierProduct> implements ISupplierProductService {
    @Autowired
    private SupplierInfoMapper supplierInfoMapper;
    @Autowired
    private SupplierProductMapper supplierProductMapper;
    /**
     * 分页查询供应商商品信息 商品维护
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<SupplierProduct> SupplierProductListPage(int sysUsersId,int currentPage, int pageSize) {
        int supplierId=supplierInfoMapper.listSupplierId(sysUsersId);
        List<SupplierProduct> goodsInfos=supplierProductMapper.page(supplierId);
        PageHelper.startPage(currentPage,pageSize);
        PageInfo<SupplierProduct> pageInfo=new PageInfo<>(goodsInfos);
        return pageInfo;
    }

    /**
     * 供应商商品拿id去查询数据
     * @param id
     * @return
     */
    @Override
    public SupplierProduct getByIdList(int id) {
        SupplierProduct supplierProduct=supplierProductMapper.getByIdPage(id);
        return supplierProduct;
    }

    @Override
    public PageUtils<SupplierGoodsDto> querySupplier(SupplierInfo supplierInfo, Long goodsId, int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        PageHelper.orderBy("price asc");

        List<SupplierGoodsDto> list = supplierProductMapper.querySupplier(supplierInfo,goodsId);

        PageInfo<SupplierGoodsDto> pageInfo = new PageInfo<>(list);
        PageUtils<SupplierGoodsDto> pageUtils = new PageUtils<>();
        pageUtils.setTotal(pageInfo.getTotal());
        pageUtils.setRows(pageInfo.getList());
        return pageUtils;
    }
}
